package com.panopset.refactorsf;

import javax.swing.JCheckBox;

import com.panopset.java.Version;
import com.panopset.sf.FontManager.FontType;
import com.panopset.sf.FontManager;
import com.panopset.sf.Windoc;

/**
 * JCheckBox persistent container.
 *
 * @author Karl Dinwiddie
 *
 */
public final class PanCheckBox extends PanNoBorderField<JCheckBox> {

    private final String lbl;

    /**
     * @param label
     *            Label.
     * @param toolTipText
     *            Tool tip text.
     */
    public PanCheckBox(final Windoc wd, final String label, final String toolTipText) {
        super(wd, Boolean.FALSE.toString(), toolTipText);
        lbl = label;
    }
    
    public PanCheckBox(final Windoc wd, final String label, final String toolTipText, final boolean dft) {
        super(wd, new Boolean(dft).toString(), toolTipText);
        lbl = label;
    }

	@Override
	protected String getGuiValue() {
		return Boolean.valueOf(getInnerComponent().isSelected())
                .toString();
	}

	@Override
	protected void setGuiValue(String value) {
		getInnerComponent().setSelected(Boolean.parseBoolean(value));
	}
    /**
     * Create a Panopset checkbox with no tool tip text.
     *
     * @param title
     *            Title.
     */
    public PanCheckBox(final Windoc wd, final String title) {
        this(wd, title, "");
    }

    @Override
    public JCheckBox createComponent() {
        JCheckBox rtn = new JCheckBox(lbl);
        rtn.setBackground(LookAndFeel.Colors.BG_COLOR.getColor());
        FontManager.getInstance().register(rtn, FontType.plainArial);
        return rtn;
    }

    @Override
    protected boolean isValid(final String valueToCheck) {
        return true;
    }

    public boolean isSelected() {
    	return isChecked();
    }
    /**
     * @return True iff user checked this box.
     */
    public boolean isChecked() {
        return getInnerComponent().isSelected();
    }
}
